home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_01 / comm1.c < prev    next >
C/C++ Source or Header  |  1993-11-19  |  50KB  |  1,661 lines

  1. /***********************************************************************/
  2. /* COMM1.C - Commands A-D                                              */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1993 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Header: C:\THE\RCS\comm1.c 1.4 1993/09/01 16:25:34 MH Interim MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /*#define DEBUG 1*/
  51.  
  52. /*-------------------------- external data ----------------------------*/
  53. extern LINE *next_line,*curr_line;
  54. extern VIEW_DETAILS *vd_current,*vd_first,*vd_mark;
  55. extern char current_screen;
  56. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  57. extern WINDOW *foot,*error_window,*divider;
  58. extern bool error_on_screen;
  59. extern char *rec;
  60. extern unsigned short rec_len;
  61. extern char *cmd_rec;
  62. extern unsigned short cmd_rec_len;
  63. extern char mode_insert;        /* defines insert mode toggle */
  64. extern char in_profile;    /* indicates if processing profile */
  65.  
  66. extern char *temp_cmd;
  67. extern char dir_filename[10];
  68. extern char dir_pathname[MAX_FILE_NAME+1];
  69. extern char sp_path[MAX_FILE_NAME+1] ;
  70. extern char sp_fname[MAX_FILE_NAME+1] ;
  71. extern char dir_path[MAX_FILE_NAME+1] ;    /* for dir and ls commands */
  72. /*man-start*********************************************************************
  73. COMMAND
  74.      add - add blank line
  75.  
  76. SYNTAX
  77.      ADD [n]
  78.  
  79. DESCRIPTION
  80.      The ADD command inserts the specified number of blank lines after
  81.      the current_line (if issued from the command line) or after the
  82.      focus_line (if issued in the main of prefix windows).
  83.      The cursor is positioned in the column corresponding to the first
  84.      column not containing a space in the line above.
  85.  
  86. COMPATIBILITY
  87.      XEDIT: Compatible.
  88.      KEDIT: Compatible.
  89.  
  90. DEFAULT
  91.      With no parameters, 1 line is added.
  92.  
  93. SEE ALSO
  94.      SOS ADDLINE
  95.  
  96. STATUS
  97.      Complete
  98. **man-end**********************************************************************/
  99. #ifdef PROTO
  100. int Add(char *params)
  101. #else
  102. int Add(params)
  103. char *params;
  104. #endif
  105. /***********************************************************************/
  106. {
  107. /*--------------------------- local data ------------------------------*/
  108. #define ADD_PARAMS  1
  109.  char *word[ADD_PARAMS+1];
  110.  char parm[ADD_PARAMS];
  111.  unsigned short num_params;
  112.  long num_lines;
  113. /*--------------------------- processing ------------------------------*/
  114. #ifdef TRACE
  115.  trace_function("comm1.c:   Add");
  116. #endif
  117. /*---------------------------------------------------------------------*/
  118. /* Validate the parameters that have been supplied. The one and only   */
  119. /* parameter should be a positive integer greater than zero.           */
  120. /* If no parameter is supplied, 1 is assumed.                          */
  121. /*---------------------------------------------------------------------*/
  122.  num_params = param_split(params,word,ADD_PARAMS,WORD_DELIMS,TEMP_PARAM);
  123.  if (num_params == 0)
  124.     {
  125.      num_params = 1;
  126.      word[0] = (char *)"1";
  127.     }
  128.  if (num_params != 1)
  129.     {
  130.      display_error(1,word[1]);
  131. #ifdef TRACE
  132.      trace_return();
  133. #endif
  134.      return(RC_INVALID_OPERAND);
  135.     }
  136.  if (!valid_positive_integer(word[0]))
  137.     {
  138.      display_error(4,word[0]);
  139. #ifdef TRACE
  140.      trace_return();
  141. #endif
  142.      return(RC_INVALID_OPERAND);
  143.     }
  144.  num_lines = atol(word[0]);
  145.  post_process_line(CURRENT_VIEW->focus_line);
  146.  insert_new_line((char *)"",0,num_lines,get_true_line(),FALSE,FALSE);
  147. #ifdef TRACE
  148.  trace_return();
  149. #endif
  150.  return(RC_OK);
  151. }
  152. /*man-start*********************************************************************
  153. COMMAND
  154.      all - select and display restricted set of lines
  155.  
  156. SYNTAX
  157.      ALL [string target]
  158.  
  159. DESCRIPTION
  160.  
  161. COMPATIBILITY
  162.      XEDIT: Compatible.
  163.      KEDIT: Compatible.
  164.  
  165. DEFAULT
  166.  
  167. SEE ALSO
  168.  
  169. STATUS
  170.      Not Started
  171. **man-end**********************************************************************/
  172. #ifdef PROTO
  173. int All(char *params)
  174. #else
  175. int All(params)
  176. char *params;
  177. #endif
  178. /***********************************************************************/
  179. {
  180. /*--------------------------- local data ------------------------------*/
  181. /*--------------------------- processing ------------------------------*/
  182. #ifdef TRACE
  183.  trace_function("comm1.c:   All");
  184. #endif
  185.  display_error(0,(char *)"This function has not yet been implemented");
  186. #ifdef TRACE
  187.  trace_return();
  188. #endif
  189.  return(RC_OK);
  190. }
  191. /*man-start*********************************************************************
  192. COMMAND
  193.      backward - scroll backwards one screen
  194.  
  195. SYNTAX
  196.      BAckward [n|*]
  197.  
  198. DESCRIPTION
  199.      The BACKWARD command scrolls the file contents backwards through
  200.      the file [n|*] screens.
  201.  
  202. COMPATIBILITY
  203.      XEDIT: Compatible.
  204.      KEDIT: Does not support HALF or Lines options.
  205.  
  206. DEFAULT
  207.      With no parameters, 1 screen is scrolled.
  208.  
  209. SEE ALSO
  210.      forward,top
  211.  
  212. STATUS
  213.      Complete
  214. **man-end**********************************************************************/
  215. #ifdef PROTO
  216. int Backward(char *params)
  217. #else
  218. int Backward(params)
  219. char *params;
  220. #endif
  221. /***********************************************************************/
  222. {
  223. /*--------------------------- local data ------------------------------*/
  224. #define BAC_PARAMS  1
  225.  char *word[BAC_PARAMS+1];
  226.  char parm[BAC_PARAMS];
  227.  register int i;
  228.  unsigned short num_params;
  229.  long num_pages,num_lines;
  230.  unsigned short x,y;
  231.  int rc;
  232. /*--------------------------- processing ------------------------------*/
  233. #ifdef TRACE
  234.  trace_function("comm1.c:   Backward");
  235. #endif
  236.  num_params = param_split(params,word,BAC_PARAMS,WORD_DELIMS,TEMP_PARAM);
  237.  if (num_params == 0)
  238.     {
  239.      num_params = 1;
  240.      word[0] = (char *)"1";
  241.     }
  242.  if (num_params != 1)
  243.     {
  244.      display_error(1,(char *)word[1]);
  245. #ifdef TRACE
  246.     trace_return();
  247. #endif
  248.      return(RC_INVALID_OPERAND);
  249.     }
  250.  if (strcmp(word[0],"*") == 0)
  251.    {
  252.     CURRENT_VIEW->current_line = 0L;
  253.     post_process_line(CURRENT_VIEW->focus_line);
  254.     CURRENT_VIEW->focus_line = 0L;
  255.     pre_process_line(CURRENT_VIEW->focus_line);
  256.     if (!in_profile)
  257.       {
  258.        if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  259.           getyx(PREVIOUS_WINDOW,y,x);
  260.        else
  261.           getyx(CURRENT_WINDOW,y,x);
  262.        show_page();
  263.        y = get_row_for_focus_line(CURRENT_VIEW->current_row,
  264.                                CURRENT_VIEW->focus_line,
  265.                                CURRENT_VIEW->current_line);
  266.        if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  267.           wmove(PREVIOUS_WINDOW,y,x);
  268.        else
  269.           wmove(CURRENT_WINDOW,y,x);
  270.       }
  271. #ifdef TRACE
  272.     trace_return();
  273. #endif
  274.     return(RC_TOF_EOF_REACHED);
  275.    }
  276.  if ((num_pages = atol(word[0])) == 0L)
  277.    {
  278.     display_error(4,(char *)word[0]);
  279. #ifdef TRACE
  280.     trace_return();
  281. #endif
  282.     return(RC_INVALID_OPERAND);
  283.    }
  284.  num_lines = CURRENT_VIEW->current_line - ((CURRENT_SCREEN.rows-1)*